home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / general.programming / comp.lang.c_10479_000012.msg < prev    next >
Encoding:
Text File  |  1994-11-27  |  2.4 KB  |  57 lines

  1. Newsgroups: comp.lang.c,comp.std.c
  2. Path: dd.chalmers.se!news.chalmers.se!sunic!EU.net!howland.reston.ans.net!cs.utexas.edu!news.unt.edu!news.oc.com!pssparc2.oc.com!lfw
  3. From: lfw@pssparc2.oc.com (Larry Weiss)
  4. Subject: Re: allocating 0 bytes with malloc()?
  5. Message-ID: <lfw.762560906@pssparc2.oc.com>
  6. Sender: usenet@ra.oc.com
  7. Organization: OpenConnect Systems, Dallas, TX
  8. References: <jeffroCL24Ks.3qr@netcom.com> <KARL.94Feb13142514@ursa-major.spdcc.com> <761528644snz@genesis.demon.co.uk> <1994Feb21.112831.1594@inmos.co.uk> <2kvpth$56i@bb29c.mdd.comm.mot.com>
  9. Distribution: na
  10. Date: Tue, 1 Mar 1994 22:28:26 GMT
  11. Lines: 44
  12. Xref: dd.chalmers.se comp.lang.c:10479 comp.std.c:1140
  13.  
  14. mitchell@mdd.comm.mot.com (Bill Mitchell) writes:
  15.  
  16. >in comp.lang.c, conor@inmos.co.uk (Conor O'Neill) said:
  17. >>However, unfortunately the issue is now moot. ANSI C says that
  18. >>malloc(0) is one of those funny little wrinkles, and as such,
  19. >>programmers must code around it.
  20.  
  21. >Where?  Section 4.10.3.3 says, in its entirety:
  22. >    4.10.3.3 The malloc Function
  23. >    
  24. >    Synopsis
  25. >        #include <stdlib.h>
  26. >        void *malloc(size_t size);
  27. >    
  28. >    Description
  29. >        The malloc function allocates space for an object whose size is
  30. >        specified by size and whose value is indeterminate.
  31. >    
  32. >    Returns
  33. >        The malloc function returns either a null pointer or a pointer to
  34. >        the allocated space.
  35.  
  36. There is additional language in the enclosing section 7.10.3 (ISO numbering, 
  37. your 4.10.3):
  38.  
  39. 7.10.3 Memory management functions
  40.  
  41.    The order and contiguity of storage allocated by sucessive calls to the
  42. calloc, malloc, and realloc functions is unspecified.  The pointer returned
  43. if the allocation succeeds is suitably aligned so that it may be assigned
  44. to a pointer to any type of object and then used to access such an object
  45. or an array of such objects in the space allocated (until the space is 
  46. explicitly freed or reallocated).  Each such allocation shall yield a 
  47. pointer to an object disjoint from any other object.  The pointer returned
  48. points to the start (lowest byte address) of the allocated space.  If
  49. the space cannot be allocated, a null pointer is returned.  If the size 
  50. of the space requested is zero, the behavior is implementation-defined;
  51. the value returned shall be either a null pointer or a unique pointer.
  52. The value of a pointer that refers to freed space is indeterminate.
  53.  
  54. -- 
  55. Larry Weiss, lfw@oc.com  
  56. 214/888-0471
  57.